package org.elj.jeasyexcel.instrospection;

import java.lang.reflect.Method;

/**
 * Facilitate introspection access
 * 
 * @author elaroche.
 */
public class IntrospectionFacility {
	@SuppressWarnings("unchecked")
	private static Class classArgs[] = {};
	private static Object methodArgs[] = {};

	/**
	 * @param instance
	 *            Object instance on which to call getter attribute
	 * @param attributeName
	 *            Name of the attribute to call getter on
	 * @return String value of the result
	 */
	@SuppressWarnings("unchecked")
	public static String getMethodReturn(Object instance, String attributeName) {
		String result = null;

		// get the Class
		Class thisClass = instance.getClass();
		// build method name
		String aMethod = "get" + attributeName.substring(0, 1).toUpperCase()
				+ attributeName.substring(1, attributeName.length());
		// get the method
		Method thisMethod;
		try {
			thisMethod = thisClass.getDeclaredMethod(aMethod, classArgs);
			result = thisMethod.invoke(instance, methodArgs).toString();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
	}
}
